<?php
// 配置文件
define('TODO_FILE', 'todos.json');
define('UPLOAD_DIR', 'upload/');

// 读取现有数据
$todos = [];
if (file_exists(TODO_FILE)) {
    $todos = json_decode(file_get_contents(TODO_FILE), true) ?: [];
}

// 处理状态修改请求
if (isset($_GET['id'])) {
    $index = (int)$_GET['id'];
    if (isset($todos[$index])) {
        $todos[$index]['status'] = 0; // 设置为未完成状态
        file_put_contents(TODO_FILE, json_encode($todos, JSON_PRETTY_PRINT));
    }
    header('Location: index.php');
    exit;
}
?>

<!DOCTYPE html>
<html>
<head>
    <style>
        .timer-btn {
            padding: 12px 24px;
            font-size: 1em;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            display: block;
            margin-bottom: 25px;
        }
        .timer-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0,0,0,0.15);
        }
        .timer-btn:active {
            transform: translateY(0);
        }
        .button-container {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-bottom: 25px;
        }
    </style>
    <title>修改作业状态</title>
</head>
<body>
    <h1>将作业标记为未完成</h1>
    <div class="button-container">
        <a href="index.php" class="timer-btn">返回首页</a>
    </div>
    <div>
        <?php foreach (array_reverse($todos, true) as $index => $item): ?>
            <?php if ($item['status'] == 1): ?>
                <div>
                    <span><?= htmlspecialchars($item['content']) ?></span>
                    <small>(<?= $item['date'] ?>)</small>
                    <button onclick="location.href='edit.php?id=<?= $index ?>'" class="timer-btn">
                        标记为未完成
                    </button>
                </div>
            <?php endif; ?>
        <?php endforeach; ?>
    </div>
    <br>
</body>
</html>